<?php
	class chudedb
	{
		public function Add($MaChuDe = "", $TenChuDe = "")
		{
			$sql = "INSERT INTO tbl_chude(MaChuDe,TenChuDe) VALUES('$MaChuDe','$TenChuDe')";
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function IssetTopics($MaChuDe = "", $TenChuDe = "")
		{
			$sql = "SELECT COUNT(*) AS SoDong FROM tbl_chude WHERE (1)";
			
			if($MaChuDe != "")
				$sql .= " AND MaChuDe = '$MaChuDe'";
			
			if($TenChuDe != "")
				$sql .= " OR TenChuDe = '$TenChuDe'";
			
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function GetListTopics($MaChuDe = "", $TenChuDe = "")
		{
			$sql = "SELECT * FROM tbl_chude WHERE (1)";
			
			if($MaChuDe != "")
				$sql .= " AND MaChuDe = '$MaChuDe'";
			
			if($TenChuDe != "")
				$sql .= " AND TenChuDe = '$TenChuDe'";
    
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		
		public function Update($MaChuDe = "", $TenChuDe = "")
		{
            echo $TenChuDe;
			$sql = "UPDATE tbl_chude SET TenChuDe = '$TenChuDe' WHERE MaChuDe = '$MaChuDe'";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaChuDe = "")
		{
			$sql = "DELETE FROM tbl_chude WHERE MaChuDe = '$MaChuDe'";			
			
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
        
        public function TotalPage($SoChuDe = 0)
        {
            $sql  = "SELECT * FROM tbl_chude ";
            $sql .= "WHERE (1)";
                
            $data = new dataservice();
            $TongSoDong = $data->ReturnNumRows($sql);
            $TongSoTrang = ceil($TongSoDong / $SoChuDe);
            return $TongSoTrang;
        }
        
        public function Paging($SoChuDe = 1, $P = 1)
        {
            $X = ($P-1) * $SoChuDe;
            $sql  = "SELECT * FROM tbl_chude ";
            $sql .= "WHERE (1)";
                
            $sql .= " LIMIT $X,$SoChuDe";
            $data = new dataservice();
            return $data->ExecuteQuery($sql);
        }
	}
?>